<template>
  <div class="main" v-loading="detailLoading">
    <el-form ref="form" size="mini" :model="form" :disabled="openType=='view'||type!='innerUse'" label-width="100px" :rules="rules">
      <el-row :gutter="24">
        <responseBox>
          <el-form-item label="特性类别" prop="scType">
            <el-select size="mini" filterable @change="scTypeChange" v-model="form.scType" placeholder="请选择特性类别" style="width: 100%;">
              <el-option v-for="item in scTypeList" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
        </responseBox>
        <responseBox v-show="form.scType==1">
          <el-form-item label="特性名称" prop="productSc">
            <el-input v-model="form.productSc" placeholder="特性名称" show-word-limit maxlength="30"></el-input>
          </el-form-item>
        </responseBox>
        <responseBox v-show="form.scType==2">
          <el-form-item label="特性名称" prop="procedureSc">
            <el-input v-model="form.procedureSc" placeholder="特性名称" show-word-limit maxlength="30"></el-input>
          </el-form-item>
        </responseBox>
        <responseBox>
          <el-form-item label="特性分类" prop="scKind">
            <el-select clearable filterable v-model="form.scKind" placeholder="请选择特性分类" style="width: 100%;">
              <el-option v-for="item in scKindList" :key="item.id" :label="item.quaType" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
        </responseBox>
      </el-row>
      <el-row :gutter="24" v-show="type=='innerUse'">
        <el-col v-if="openType=='view'">
          <el-form-item label="特殊特性标识" prop="acceptNo">
            <div>
              <img v-show="form.notation" style="width: 30px; height:25px;vertical-align: middle;" :src="form.notation" alt="">
            </div>
          </el-form-item>
        </el-col>
        <el-col v-else>
          <el-form-item label="特殊特性标识" prop="acceptNo">
            <el-radio-group v-model="form.drawingScFlag" class="radio_group_self">
              <el-radio v-for="item in specialSymnols" :key="item.id" :label="item.id">
                <img style="width: 30px; height: 25px; vertical-align: middle;" :src="item.notation">
              </el-radio>
              <el-radio label="1">
                <span style="display: inline-block; width: 30px; height: 25px; line-height: 25px; font-size: 12px;">取消</span>
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <avue-crud ref="infoCrud" :option="infoOption" :data="infoData">
      <template slot="menuLeft">
        <el-button type="text" icon="el-icon-plus" @click="addInfoRow('characteristic')">新增</el-button>
        <!-- <el-button type="text" icon="el-icon-plus" @click="addInfoRow('capacity')">新增容量</el-button> -->
      </template>
      <!-- 规范录入方式 -->
      <template slot="standardType" slot-scope="{row}">
        <span v-if="!row.isEdit">{{standardTypeObj[row.standardType]}}</span>
        <el-select size="mini" v-else v-model="row.standardType" @change="stardandTypeChange(row)">
          <el-option v-for="item in standardTypeList" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </template>
      <!-- 检验规范 -->
      <template slot-scope="{row}" slot='standardDesc'>
        <div v-if="row.isEdit">
          <el-input v-if="row.standardType=='1'" size="mini" v-model="row.standard"></el-input>
          <el-button style="width: 100%" v-else-if="row.standardType=='2'" type="text" size="mini" @click="selectStandard(row)">选择</el-button>
          <el-upload style="width: 100%" class="upLoad_pic" v-else action="/api/attach/uploadFile" :on-error="uploadError" :headers="headers" :on-success="handleSuccess" :show-file-list="false" :before-upload="beforeUpload">
            <el-button :loading="row.uploadLoading" style="width: 100%" size="small" type="text" @click="uploadClick(row)">上传</el-button>
          </el-upload>
          <!-- <el-select v-else size="mini" v-model="row.standardDesc" @change="stardandPicChange(row)">
            <el-option v-for="item in standardList" :key="item.id" :label="item.standardDesc" :value="item.standardUrl">
              <div style="width: 100%; display: flex; align-items: center; justify-content: space-between;">
                <span>{{item.standardDesc}}</span>
                <img style="width:120px; height: auto; vertical-align: middle;" :src="item.standardUrl" alt="">
              </div>
            </el-option>
          </el-select> -->
        </div>
        <div v-else>
          <span v-if="row.standardType=='1'">{{row.standard}}</span>
        </div>
      </template>
      <template slot-scope="{row}" slot='standard'>
        <div style="width: 100%; height: 40px;">
          <el-image v-show="row.standardType!=1&&row.standard" style="width: 90px; height: 36px;" :src="row.standard" :preview-src-list="[row.standard]">
          </el-image>
        </div>
      </template>
      <!-- 样本容量 -->
      <template slot="capacity" slot-scope="{row}">
        <span v-if="!row.isEdit">{{row.capacity}}</span>
        <el-input v-else v-model="row.capacity" size="mini" placeholder="样本容量"></el-input>
      </template>
      <!-- 样本频率 -->
      <template slot="frequency" slot-scope="{row}">
        <!-- <span v-if="!row.isEdit">{{frequencyObj[row.frequency]}}</span>
        <el-select filterable size="mini" v-else v-model="row.frequency">
          <el-option v-for="item in frequencyList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
        </el-select> -->
        <span v-if="!row.isEdit">{{row.frequency}}</span>
        <el-input v-else size="mini" v-model="row.frequency" maxlength="25"></el-input>
      </template>
      <!-- 测量技术 -->
      <template slot="technology" slot-scope="{row}">
        <span v-if="!row.isEdit">{{row.technology}}</span>
        <el-input v-else v-model="row.technology" size="mini" placeholder="测量技术"></el-input>
      </template>
      <!-- 测量设备 -->
      <template slot="fixtureNo" slot-scope="{row}">
        <!-- <span v-if="!row.isEdit">{{fixtureNoObj[row.fixtureNo]}}({{row.fixtureNo}})</span> -->
        <div v-if="!row.isEdit">
          <div v-for="item in row.fixtureNo1" :key="item">
            {{fixtureNoObj[item]}}({{item}})
          </div>
        </div>
        <!-- <el-select size="mini" filterable clearable v-else v-model="row.fixtureNo1" multiple>
          <el-option v-for="item in fixtureNoList" :key="item.materialNo" :label="item.materialName" :value="item.materialNo">
            <span>{{item.materialName}}({{item.materialNo}})</span>
          </el-option>
        </el-select> -->
        <div v-else>
          <div v-for="item in row.fixtureNo1" :key="item">
            {{fixtureNoObj[item]}}({{item}})
          </div>
          <div @click="showFixture(row)">
            <i style="font-size: 14px; color: #409eff; cursor: pointer;" class="el-icon-edit-outline"></i>
          </div>
        </div>
      </template>
      <!-- 检测方法 -->
      <template slot="testMethod" slot-scope="{row}">
        <span v-if="!row.isEdit">{{testMethodObj[row.testMethod]}}</span>
        <el-select size="mini" v-else v-model="row.testMethod" @change="testMethodChange(row)">
          <el-option v-for="item in testMethodList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
        </el-select>
      </template>
      <!-- 公差计算方法 -->
      <template slot="calculationMethod" slot-scope="{row}">
        <span v-if="!row.isEdit">{{calculationMethodObj[row.calculationMethod]}}</span>
        <el-select size="mini" v-else v-model="row.calculationMethod" @change="calculationMethodChagne(row)">
          <el-option v-for="item in calculationMethodList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
        </el-select>
      </template>
      <!-- 最大值 -->
      <template slot="maximumValue" slot-scope="{row}">
        <span v-if="!row.isEdit||!row.needMaxVal">{{row.maximumValue}}</span>
        <el-input v-Doctfour maxlength="7" v-else v-model="row.maximumValue" size="mini" placeholder="最大值"></el-input>
      </template>
      <!-- 最小值 -->
      <template slot="minimumValue" slot-scope="{row}">
        <span v-if="!row.isEdit||!row.needMinVal">{{row.minimumValue}}</span>
        <el-input v-Doctfour maxlength="7" v-else v-model="row.minimumValue" size="mini" placeholder="最小值"></el-input>
      </template>
      <!-- 标准值 -->
      <template slot="standardValue" slot-scope="{row}">
        <span v-if="!row.isEdit||!row.needStandardValue">{{row.standardValue}}</span>
        <el-input v-Doctdefault1 maxlength="7" v-else v-model="row.standardValue" size="mini" placeholder="标准值"></el-input>
      </template>
      <!-- 正公差 -->
      <template slot="positiveTolerance" slot-scope="{row}">
        <span v-if="!row.isEdit||!row.needPositiveTolerance">{{row.positiveTolerance}}</span>
        <el-input v-Doctdefault1 maxlength="7" v-else v-model="row.positiveTolerance" size="mini" placeholder="正公差"></el-input>
      </template>
      <!-- 负公差 -->
      <template slot="negativeTolerance" slot-scope="{row}">
        <span v-if="!row.isEdit||!row.needNegativeTolerance">{{row.negativeTolerance}}</span>
        <el-input v-Doctdefault1 maxlength="7" v-else v-model="row.negativeTolerance" size="mini" placeholder="负公差"></el-input>
      </template>
      <!-- 特征符号 -->
      <template slot="characteristic" slot-scope="{row}">
        <span v-if="!row.isEdit">{{characteristicObj[row.characteristic]}}</span>
        <el-select size="mini" v-else v-model="row.characteristic">
          <el-option v-for="item in characteristicList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
        </el-select>
      </template>
      <!-- 菜单 -->
      <template slot-scope="{row}" slot="menu">
        <el-tooltip class="item" effect="dark" content="复制" placement="bottom">
          <el-button icon="el-icon-plus" size="small" type="text" @click="addInfoRow('capacity', row)"></el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="删除" placement="bottom">
          <el-button icon="el-icon-delete" size="small" type="text" @click.stop="inforRowDel(row,row.$index)" v-if="permission.publiccraft_feature_delete"></el-button>
        </el-tooltip>
      </template>
    </avue-crud>
    <div class="center mt">
      <el-button icon="el-icon-circle-plus-outline" :loading="saveLoading" type="primary" v-show="openType!='view'" size="mini" @click="saveFn">保 存</el-button>
      <el-button icon="el-icon-circle-close" :loading="saveLoading" size="mini" @click="$emit('close')">取 消</el-button>
    </div>
    <el-dialog v-dialogdrag top="15vh" title="选择检验规范" :visible.sync="showStandards" width="400px" append-to-body>
      <standards @selectFinish="selectFinish" :productId="productId" v-if="showStandards"/>
    </el-dialog>
    <el-dialog v-dialogdrag top="15vh" title="测量设备" :visible.sync="showEquipment" width="1000px" append-to-body>
      <div class="self_transfer">
        <el-transfer :titles="['未选', '已选']" filterable v-model="rowFixtureNos" :data="fixtureNoList" :props="{label: 'label', key: 'materialNo'}"></el-transfer>
      </div>
      <div class="center mt">
        <el-button size="mini" type="primary" @click="confirmTransfer">确 定</el-button>
        <el-button size="mini" @click="closeTransfer">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import responseBox from '@/components/base-small/response-box.vue'
import {getSpecialSymbols} from '@/api/publicbasic/specialSymbols.js'
import { updateFeature, getFeature, addStandardFn, getStandardFn, editStandardFn } from '@/api/project/productData/processData'
import { getQualityList } from '@/api/project/information/base'
import { getBusinessList } from '@/api/zidian'
import { mapGetters, mapState } from 'vuex'
import {getInspectionStandards} from '@/api/publicbasic/inspectionSpecification.js'
import { getEquipments } from '@/api/project/productData/equipment'
import {savePics} from '@/api/publicbasic/inspectionSpecification.js'
import standards from './featureStandards'
export default {
  name: 'MainCom',
  props: ['rowInfo','openType','type','productId'],
  components: {
    responseBox,
    standards
  },
  computed: {
    ...mapGetters(['userInfo', 'permission']),
    ...mapState({
      headers: state => ({'Blade-Auth':`bearer ${state.user.token}`})
    }),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.publiccraft_feature_add, false),
        viewBtn: this.vaildData(this.permission.publiccraft_feature_view, false),
        delBtn: this.vaildData(this.permission.publiccraft_feature_delete, false),
        editBtn: this.vaildData(this.permission.publiccraft_feature_edit, false),
      };
    },
  },
  data () {
    return {
      showEquipment: false,
      fixtures: [],
      standardRow: [],
      rowFixtureNos: [],
      scTypeList: [
        {
          label: '产品特性',
          value: '1'
        },
        {
          label: '过程特性',
          value: '2'
        }
      ],
      uploadRow: {},
      showStandards: false,
      standardTypeList: [
        {
          label: '输入',
          value: '1',
        },
        {
          label: '选择',
          value: '2',
        },
        {
          label: '上传',
          value: '3',
        },
      ],
      standardTypeObj: {
        '1': '输入',
        '2': '选择',
        '3': '上传',
      },
      standardList: [],
      // frequencyList: [],
      // frequencyObj: {},
      fixtureNoList: [],
      fixtureNoObj: {},
      testMethodList: [],
      testMethodObj: {},
      calculationMethodList: [],
      calculationMethodObj: {},
      characteristicList: [],
      characteristicObj: {},
      scKindList: [],
      detailLoading: false,
      saveLoading: false,
      form: {},
      specialSymnols: [],
      infoData: [],
      infoOption: {
        dialogHeight: '100%',
        dialogWidth: '600',
        page: false,
        tip: false,
        border: true,
        index: true,
        indexLabel: '序号',
        // selection: true,
        viewBtn: false,
        delBtn: false,
        editBtn: false,
        addBtn: false,
        menuWidth: 70,
        columnBtn: true,
        filterBtn: true,
        dialogClickModal: false,
        labelWidth: 120,
        header: true,
        menu: true,
        column: [
          {
            label: '规范录入方式',
            prop: 'standardType',
            minWidth: '95',
            slot: true,
            fixed: true,
          },
          {
            label: '检验规范',
            prop: 'standardDesc',
            slot: true,
            minWidth: 140,
            fixed: true,
          },
          {
            label: '检验规范图片',
            prop: 'standard',
            slot: true,
            minWidth: 120,
            fixed: true,
          },
          {
            label: '样本容量',
            prop: 'capacity',
            slot: true,
            minWidth: 80
          },
          {
            label: '样本频率',
            prop: 'frequency',
            slot: true,
            minWidth: 150
          },
          {
            label: '测量技术',
            prop: 'technology',
            slot: true,
            minWidth: 120
          },
          {
            label: '测量设备',
            prop: 'fixtureNo',
            slot: true,
            minWidth: 180
          },
          {
            label: '检测方法',
            prop: 'testMethod',
            slot: true,
            minWidth: 100
          },
          {
            label: '公差计算方法',
            prop: 'calculationMethod',
            slot: true,
            minWidth: 120
          },
          {
            label: '最小值',
            prop: 'minimumValue',
            slot: true,
            minWidth: 86
          },
          {
            label: '最大值',
            prop: 'maximumValue',
            slot: true,
            minWidth: 86
          },
          {
            label: '标准值',
            prop: 'standardValue',
            slot: true,
            minWidth: 86
          },
          {
            label: '正公差',
            prop: 'positiveTolerance',
            slot: true,
            minWidth: 86
          },
          {
            label: '负公差',
            prop: 'negativeTolerance',
            slot: true,
            minWidth: 86
          },
          {
            label: '特征符号',
            prop: 'characteristic',
            slot: true,
            minWidth: 130
          },
        ],
      },
      rules: {
        // scKind: [
        //   {required: true, message: '请选择特性分类', trigger: 'change'}
        // ]
      },
    }
  },
  created () {
    if (this.openType=='view') {
      this.infoOption.menu = false
      this.infoOption.header = false
    }
    getSpecialSymbols().then(res => {
      this.specialSymnols = res.data.data
    })
    getInspectionStandards().then(res => {
      this.standardList = res.data.data
    })
    // getBusinessList('scFrequency').then((res) => {
    //   this.frequencyList = res.data.data.map(item => {
    //     this.frequencyObj[item.dictKey] = item.dictValue
    //     return item
    //   })
    // });
    getBusinessList('testMethod').then((res) => {
      this.testMethodList = res.data.data.map(item => {
        this.testMethodObj[item.dictKey] = item.dictValue
        return item
      })
    });
    getBusinessList('calculationMethod').then((res) => {
      this.calculationMethodList = res.data.data.map(item => {
        this.calculationMethodObj[item.dictKey] = item.dictValue
        return item
      })
    });
    getBusinessList('specialSymbols').then((res) => {
      this.characteristicList = res.data.data.map(item => {
        this.characteristicObj[item.dictKey] = item.dictValue
        return item
      })
    });
    getEquipments({ materialType: 'EJ' }).then((res) => {
      this.fixtureNoList = res.data.data.map(item => {
        item.label = item.materialName + `(${item.materialNo})`
        // this.fixtureNoObj[item.materialNo] = item.materialName
        this.$set(this.fixtureNoObj,item.materialNo,item.materialName)
        return item
      })
    });
    getQualityList().then((res) => {
      this.scKindList = res.data.data.map(item => {
        item.quaType = item.quaType + '-' + item.definition
        return item
      })
    });
    if (this.type=='innerUse') {
      this.detailLoading = true
      getFeature(this.rowInfo.id).then((res) => {
        this.form = res.data.data;
        this.infoData = res.data.data.itemVOS.map(item => {
          item.isEdit = this.openType == 'view' ? false : true
          item.standardDesc = item.standard
          this.$set(item,'fixtureNo1', item.fixtureNo ? item.fixtureNo.split(',') : [])
          if (item.calculationMethod == 1) {
            this.$set(item, 'needMaxVal', true)
            this.$set(item, 'needMinVal', true)
          } else if (item.calculationMethod == 2) {
            this.$set(item, 'needStandardValue', true) // 标准值
            this.$set(item, 'needPositiveTolerance', true) // 正公差
            this.$set(item, 'needNegativeTolerance', true) // 负公差
          } else if (item.calculationMethod == 3) {
            this.$set(item, 'needMaxVal', true)
          } else if (item.calculationMethod == 4) {
            this.$set(item, 'needMinVal', true)
          }
          return item
        })
        this.detailLoading = false
      });
    } else {
      if (this.openType=='addStandard') {
        this.form = this.rowInfo
      }
      if (this.openType=='editStandard') {
        this.form = this.rowInfo
        this.infoOption.menu = false
        this.infoOption.header = false
        this.detailLoading = true
        getStandardFn(this.form.productScId).then(res => {
          let data = res.data.data
          data.isEdit = true
          data.standardDesc = data.standard
          data.fixtureNo1 = data.fixtureNo ? data.fixtureNo.split(',') : []
          if (data.calculationMethod == 1) {
            this.$set(data, 'needMaxVal', true)
            this.$set(data, 'needMinVal', true)
          } else if (data.calculationMethod == 2) {
            this.$set(data, 'needStandardValue', true) // 标准值
            this.$set(data, 'needPositiveTolerance', true) // 正公差
            this.$set(data, 'needNegativeTolerance', true) // 负公差
          } else if (data.calculationMethod == 3) {
            this.$set(data, 'needMaxVal', true)
          } else if (data.calculationMethod == 4) {
            this.$set(data, 'needMinVal', true)
          }
          this.infoData = [data]
          this.detailLoading = false
        })
      }
    }
  },
  methods: {
    showFixture (row) {
      console.log(row)
      this.rowFixtureNos = [...row.fixtureNo1]
      this.standardRow = row
      this.showEquipment = true
    },
    closeTransfer () {
      this.rowFixtureNos = []
      this.showEquipment = false
    },
    confirmTransfer () {
      this.standardRow.fixtureNo1 = [...this.rowFixtureNos]
      this.showEquipment = false
      this.rowFixtureNos = []
    },
    scTypeChange (val) {
      if (val==1) {
        this.form.productSc = this.form.procedureSc
        this.form.procedureSc = ''
      } else {
        this.form.procedureSc = this.form.productSc
        this.form.productSc = ''
      }
    },
    selectionChange (list) {
      this.selectionList = list
    },
    selectStandard (row) {
      this.showStandards = true
      this.uploadRow = row
    },
    selectFinish (data) {
      this.uploadRow.standard = data.standardUrl
      this.showStandards = false
    },
    uploadClick (row) {
      this.uploadRow = row
    },
    beforeUpload (file) {
      this.$set(this.uploadRow, 'uploadLoading', true)
      var reg = /^.*\.(?:jpg|jpeg|png)$/i;
      if (!reg.test(file.name)) {
        this.$message.error('请上传jpg、jpeg或png格式文件!');
        this.$set(this.uploadRow, 'uploadLoading', false)
        return false;
      }
      const isLt10M = file.size / 1024 / 1024 < 10;
      if (!isLt10M) {
        this.$message.error(`上传文件大小不能超过 10MB!`);
        this.$set(this.uploadRow, 'uploadLoading', false)
        return false
      }
      return true
    },
    handleSuccess (response) {
      this.$set(this.uploadRow, 'uploadLoading', false)
      this.uploadRow.newUpload = true
      this.uploadRow.standard = response.data.link
    },
    uploadError () {
      this.$message.error('上传失败')
      this.$set(this.uploadRow, 'uploadLoading', false)
    },
    inforRowDel(row, index) {
      this.$confirm('确定将此数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.infoData.splice(index, 1);
      });
    },
    stardandTypeChange (row) {
      // if (row.standardType=='1') {
      //   this.findObject(this.infoOption.column, 'standardDesc').label = '检验规范'
      // } else {
      //   this.findObject(this.infoOption.column, 'standardDesc').label = '检验规范描述'
      // }
      row.standard = ''
      row.standardDesc = ''
    },
    stardandPicChange (row) {
      // row.standard = this.standardList.find(item => item.id == row.standardDesc).standardUrl
      row.standard = row.standardDesc
    },
    addInfoRow (type,row) {
      if (type == 'characteristic') { // 特性
        this.infoData.push({
          standardType: '1',
          standardDesc: '',
          standard: '',
          capacity: '',
          frequency: '',
          technology: '',
          fixtureNo1: [],
          testMethod: '',
          calculationMethod: '',
          maximumValue: '',
          minimumValue: '',
          standardValue: '',
          positiveTolerance: '',
          negativeTolerance: '',
          characteristic: '',
          isEdit: true,
        })
      } else {
        let item = {
          standardType: row.standardType,
          standardDesc: row.standardDesc,
          standard: row.standard,
          capacity: row.capacity,
          frequency: row.frequency,
          technology: row.technology,
          fixtureNo1: row.fixtureNo1,
          testMethod: row.testMethod,
          calculationMethod: row.calculationMethod,
          maximumValue: row.maximumValue,
          minimumValue: row.minimumValue,
          standardValue: row.standardValue,
          positiveTolerance: row.positiveTolerance,
          negativeTolerance: row.negativeTolerance,
          characteristic: row.characteristic,
          needMaxVal: row.needMaxVal,
          needMinVal: row.needMinVal,
          needStandardValue: row.needStandardValue,
          needPositiveTolerance: row.needPositiveTolerance,
          needNegativeTolerance: row.needNegativeTolerance,
          isEdit: true,
        }
        this.infoData.splice(row.$index+1, 0, item)
      }
    },
    saveFn () {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.infoData.forEach(item => {
            item.fixtureNo = item.fixtureNo1.join(',')
          })
          this.form.itemVOS = this.infoData
          // if (!this.form.productSc&&!this.form.procedureSc) {
          //   this.$message.warning('产品特性或过程特性必填一项')
          //   return
          // }
          if (this.form.scType==1&&!this.form.productSc) {
            this.$message.error(`请维护产品特性`)
            return
          }
          if (this.form.scType==2&&!this.form.procedureSc) {
            this.$message.error(`请维护过程特性`)
            return
          }
          for (let i=0; i<this.infoData.length; i++) {
            if (!this.infoData[i].standard) {
              this.$message.warning(`第${i+1}行 ${this.infoData[i].standardType==2?'请选择':'请输入'}检验规范`)
              return
            }
            // if (!this.infoData[i].capacity) {
            //   this.$message.warning(`第${i+1}行 请输入样本容量`)
            //   return
            // }
            // if (!this.infoData[i].frequency) {
            //   this.$message.warning(`第${i+1}行 请选择样本频率`)
            //   return
            // }
            // if (!this.infoData[i].technology&&!this.infoData[i].fixtureNo) {
            //   this.$message.error(`第${i+1}行 测量技术和测量设备至少填一个`)
            //   return
            // }
            if (this.infoData[i].needCalculationMethod&&!this.infoData[i].calculationMethod) {
              this.$message.error(`第${i+1}行 请选择公差计算方法`)
              return
            }

            if (this.infoData[i].needMaxVal&&!this.infoData[i].maximumValue) {
              this.$message.error(`第${i+1}行 请输入最大值`)
              return
            }
            if (this.infoData[i].needMinVal&&!this.infoData[i].minimumValue) {
              this.$message.error(`第${i+1}行 请输入最小值`)
              return
            }
            if (this.infoData[i].needStandardValue&&!this.infoData[i].standardValue) {
              this.$message.error(`第${i+1}行 请输入标准值`)
              return
            }
            if (this.infoData[i].calculationMethod == 2 && !this.infoData[i].positiveTolerance && !this.infoData[i].negativeTolerance) {
              this.$message.error(`第${i+1}行 正公差和负公差至少填一个`)
              return
            }
            if (this.infoData[i].maximumValue && this.infoData[i].minimumValue && this.infoData[i].minimumValue * 1 > this.infoData[i].maximumValue * 1) {
              this.$message.error(`第${i+1}行 最小值应该小于最大值`)
              return false;
            }
          }
          this.saveLoading = true
          if (this.type=='innerUse') { // 特性清单页面用
            let picData = []
            this.form.itemVOS.forEach(item => {
              if (item.standardType==3&&item.newUpload) {
                picData.push({
                  productId: this.productId,
                  standardDesc: '',
                  standardUrl: item.standard
                })
              }
            })
            if (picData.length>0) {
              savePics(picData)
            }
            updateFeature(this.form).then(res => {
              this.$message.success(res.data.msg)
              this.$emit('reload')
              this.saveLoading = false
            }).catch(() => {
              this.saveLoading = false
            })

          }
          // 其他页面用
          if (this.openType=='addStandard') {
            this.infoData.forEach(item => {
              item.prdProcedureId = this.rowInfo.procedureId // 工序Id
              item.scListId = this.rowInfo.scListId // 特性Id
            })
            addStandardFn(this.infoData).then(res => {
              this.$message.success(res.data.msg)
              let data = res.data.data.map(item => {
                // item.productSc = item.id
                item.procedureSc = this.form.procedureSc,
                item.scKind = this.form.scKind
                return item
              })
              this.$emit('addStandardFinish', {scListId: this.rowInfo.scListId,data})
              this.saveLoading = false
            }).catch(() => {
              this.saveLoading = false
            })
          }
          if (this.openType=='editStandard') {
            if(this.infoData[0].standardType==3&&this.infoData[0].newUpload) {
              savePics([{
                productId: this.productId,
                standardDesc: '',
                standardUrl: this.infoData[0].standard
              }])
            }
            editStandardFn(this.infoData[0]).then(res => {
              this.$message.success(res.data.msg)
              this.saveLoading = false
              let data = res.data.data
              this.$emit('editStandardFinish', data)
            }).catch(() => {
              this.saveLoading = false
            })
          }
        }
      })
    },
    testMethodChange (row) {
      if (row.testMethod == 1) {
        this.$set(row, 'needCalculationMethod', false)
      } else {
        this.$set(row, 'needCalculationMethod', true)
      }
    },
    calculationMethodChagne (row) {
      this.$set(row, 'needMaxVal', false) // 最大值
      this.$set(row, 'needMinVal', false) // 最小值
      this.$set(row, 'needStandardValue', false) // 标准值
      this.$set(row, 'needPositiveTolerance', false) // 正公差
      this.$set(row, 'needNegativeTolerance', false) // 负公差
      row.maximumValue = ''
      row.minimumValue = ''
      row.standardValue = ''
      row.positiveTolerance = ''
      row.negativeTolerance = ''
      if (row.calculationMethod == 1) {
        this.$set(row, 'needMaxVal', true)
        this.$set(row, 'needMinVal', true)
      } else if (row.calculationMethod == 2) {
        this.$set(row, 'needStandardValue', true) // 标准值
        this.$set(row, 'needPositiveTolerance', true) // 正公差
        this.$set(row, 'needNegativeTolerance', true) // 负公差
      } else if (row.calculationMethod == 3) {
        this.$set(row, 'needMaxVal', true)
      } else if (row.calculationMethod == 4) {
        this.$set(row, 'needMinVal', true)
      }
    },
  }
}
</script>

<style scoped lang="scss">
.radio_group_self /deep/ .el-radio {
  margin: 0px 14px 0px 0;
}
.upLoad_pic /deep/ .el-upload--text {
  width: 100%;
}
.self_transfer /deep/ .el-transfer {
  align-items: center;
}
.self_transfer /deep/ .el-transfer-panel {
  width: 340px;
}
</style>
